from twisted.internet import reactor
from twisted.web import server
from twisted.web import static
from twisted.web.resource import Resource
from pyamf.remoting.gateway.twisted import TwistedGateway

from common import config
from resource.rootResource import RootResource


class Server:
    services = {}
    
    def __init__(self):
        gateway = TwistedGateway(self.services, expose_request=False)
        self.root = Resource()
        self.root.putChild("", RootResource())
        self.root.putChild("gateway", gateway)
        self.root.putChild("template", static.File("template/"))
        self.root.putChild("flash", static.File("flash/"))
        self.root.putChild("crossdomain.xml", static.File("flash/crossdomain.xml"))

    def start_server(self):
        reactor.listenTCP(config.SERVER_PORT, server.Site(self.root))
        reactor.run()
